/*
 * Copyright (C) 2021 Fastjrun, Inc. All Rights Reserved.
 */
package com.fastjrun.security.service.impl;

import com.fastjrun.share.demo.security.vo.UserDetailsVO;
import com.fastjrun.share.demo.dao.SysUserDao;
import com.fastjrun.share.demo.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private SysUserDao sysUserDao;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = sysUserDao.findByUsername(username);
        if(sysUser == null) {
            throw new UsernameNotFoundException("用户名或密码错误");
        }
        UserDetailsVO userDetailVO = new UserDetailsVO();
        userDetailVO.setSysUser(sysUser);

        return userDetailVO;
    }
}
